# -*- coding: utf-8 -*-

from PySide.QtGui import *
from PySide.QtCore import *
import sys

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))

class MyPalette(QDialog):
    def __init__(self,parent=None):
        super(MyPalette, self).__init__(parent)
        self.setWindowTitle(self.tr("QPalette对话框"))

        mainLayout=QHBoxLayout(self)
        self.ctrlFrme=QFrame()
        self.contentFrame=QFrame()
        self.contentFrame.setAutoFillBackground(True)
        self.createCtrlFrame()
        self.createContentFrame()
        mainLayout.addWidget(self.ctrlFrme)
        mainLayout.addWidget(self.contentFrame)


    def createCtrlFrame(self):
        wndLabel = QLabel(self.tr("QPalette.Window"))
        wndTextLabel = QLabel(self.tr("QPalette.WindowText"))
        btnLabel = QLabel(self.tr("QPalette.Button"))
        btnTextLabel = QLabel(self.tr("QPalette.ButtonText"))
        baseLabel = QLabel(self.tr("QPalette.Base"))

        self.wndCombox = QComboBox()
        self.wndTextCombox = QComboBox()
        self.btnCombox = QComboBox()
        self.btnTextCombox = QComboBox()
        self.baseCombox = QComboBox()

        self.fillColorList(self.wndCombox)
        self.fillColorList(self.wndTextCombox)
        self.fillColorList(self.btnCombox)
        self.fillColorList(self.btnTextCombox)
        self.fillColorList(self.baseCombox)


        gridLeftLayout = QGridLayout()
        gridLeftLayout.addWidget(wndLabel, 0, 0)
        gridLeftLayout.addWidget(self.wndCombox, 0, 1)
        gridLeftLayout.addWidget(wndTextLabel, 1, 0)
        gridLeftLayout.addWidget(self.wndTextCombox, 1, 1)
        gridLeftLayout.addWidget(btnLabel, 2, 0)
        gridLeftLayout.addWidget(self.btnCombox, 2, 1)
        gridLeftLayout.addWidget(btnTextLabel, 3, 0)
        gridLeftLayout.addWidget(self.btnTextCombox, 3, 1)
        gridLeftLayout.addWidget(baseLabel, 4, 0)
        gridLeftLayout.addWidget(self.baseCombox, 4, 1)

        self.ctrlFrme.setLayout(gridLeftLayout)

    def createContentFrame(self):
        pass

    def fillColorList(self,comboBox):
        colorList=QColor.colorNames()

        for color in colorList:
            pix=QPixmap(QSize(70,20))
            pix.fill(QColor(color))
            comboBox.addItem(QIcon(pix),color)
            comboBox.setIconSize(QSize(70,20))
            comboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents)

    def panelFrameMethodOne(self):
        wndLabel = QLabel(self.tr("QPalette.Window"))
        wndTextLabel = QLabel(self.tr("QPalette.WindowText"))
        btnLabel = QLabel(self.tr("QPalette.Button"))
        btnTextLabel = QLabel(self.tr("QPalette.ButtonText"))
        baseLabel = QLabel(self.tr("QPalette.Base"))

        wndCombox = QComboBox()
        wndTextCombox = QComboBox()
        btnCombox = QComboBox()
        btnTextCombox = QComboBox()
        baseCombox = QComboBox()

        gridLeftLayout = QGridLayout()
        gridLeftLayout.addWidget(wndLabel, 0, 0)
        gridLeftLayout.addWidget(wndCombox, 0, 1)
        gridLeftLayout.addWidget(wndTextLabel, 1, 0)
        gridLeftLayout.addWidget(wndTextCombox, 1, 1)
        gridLeftLayout.addWidget(btnLabel, 2, 0)
        gridLeftLayout.addWidget(btnCombox, 2, 1)
        gridLeftLayout.addWidget(btnTextLabel, 3, 0)
        gridLeftLayout.addWidget(btnTextCombox, 3, 1)
        gridLeftLayout.addWidget(baseLabel, 4, 0)
        gridLeftLayout.addWidget(baseCombox, 4, 1)

        chooseWordLabel = QLabel(self.tr("请选择一个值："))
        chooseWordEdit = QLineEdit()

        enterCharLabel = QLabel(self.tr("请输入字符串："))
        enterCharEdit = QLineEdit()
        textEdit = QTextEdit()

        okButton = QPushButton(self.tr("确定"))
        cancelButton = QPushButton(self.tr("取消"))

        btnLayout = QHBoxLayout()
        btnLayout.addWidget(okButton)
        btnLayout.addWidget(cancelButton)

        gridRightLayout = QGridLayout()
        gridRightLayout.addWidget(chooseWordLabel, 0, 0)
        gridRightLayout.addWidget(chooseWordEdit, 0, 1)
        gridRightLayout.addWidget(enterCharLabel, 1, 0)
        gridRightLayout.addWidget(enterCharEdit, 1, 1)
        gridRightLayout.addWidget(textEdit, 2, 0, 1, 2)
        gridRightLayout.addLayout(btnLayout, 3, 0, 1, 2)

        layout = QHBoxLayout(self)
        layout.addLayout(gridLeftLayout)
        layout.addLayout(gridRightLayout)

if __name__ == "__main__":
    app=QApplication(sys.argv)
    myPalette=MyPalette()
    myPalette.show()
    sys.exit(app.exec_())